package com.qianyu.api.controller.front;

import com.qianyu.core.entity.base.Result;
import com.qianyu.core.entity.dto.UserDTO;
import com.qianyu.core.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "前台管理-用户管理", description = "wangzhicheng")
@RestController
@RequestMapping("/front/user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    /**
     * 服务商查询下级（普通用户）
     */
    @GetMapping(value = "/getUsers")
    @ApiOperation(value = "服务商查询下级（普通用户）")
    Result<List<UserDTO.UserSimpleDTO>> getUsers(){
        return Result.success(userService.getUsers());
    }

    /**
     * 注册普通用户
     * @param dto
     * @return
     */
    @PostMapping(value = "/register")
    @ApiOperation(value = "注册普通用户")
    Result<String> registerUser(@RequestBody @Validated UserDTO.UserRegisterDTO dto){
        userService.registerUser(dto);
        return Result.success();
    }

    /**
     * 修改用户信息
     */
    @PostMapping("/changeUserInfo")
    @ApiOperation(value = "修改用户信息")
    Result<String> changeUserInfo(@Validated @RequestBody UserDTO.UserUpdateDto dto) {
        userService.changeUserInfoByFront(dto);
        return Result.success();
    }

    /**
     * 修改用户密码
     */
    @PostMapping("/changePassword")
    @ApiOperation(value = "修改用户密码")
    Result<String> changePassword(@Validated @RequestBody UserDTO.PasswordDto dto) {
        userService.changePassword(dto);
        return Result.success();
    }
}
